/*
 * Copyright(C) 2019 FUYUN DATA SERVICES CO.,LTD. - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 * 该源代码版权归属福韵数据服务有限公司所有
 * 未经授权，任何人不得复制、泄露、转载、使用，否则将视为侵权
 *
 */

const fs = require('fs');
const fileTypeArray = ['js', 'ts', 'jsx', 'tsx'];
const appendString =
  '/**\n' +
  ' * Copyright(C) 2019 FUYUN DATA SERVICES CO., LTD. - All Rights Reserved\n' +
  ' * Unauthorized copying of this file, via any medium is strictly prohibited\n' +
  ' * Proprietary and confidential\n' +
  ' * 该源代码版权归属福韵数据服务有限公司所有\n' +
  ' * 未经授权，任何人不得复制、泄露、转载、使用，否则将视为侵权\n' +
  ' */\n\n';
function doAppendString(path) {
  const oPath = fs.readdirSync(path, 'utf8');
  oPath.forEach(function(item) {
    let newPath = `${path}/${item}`;
    if (fs.statSync(newPath).isDirectory()) {
      doAppendString(newPath); //是文件夹
    } else {
      const newString = fs.readFileSync(newPath, 'utf8');

      const fileType =
        item.includes('.') &&
        item
          .split('.')
          .pop()
          .toLocaleLowerCase();
      if (
        fileType &&
        fileTypeArray.includes(fileType) &&
        !newString.includes('Copyright(C)')
      ) {
        fs.writeFileSync(newPath, appendString + newString, 'utf8');
      }
    }
  });
}
doAppendString('src');
